import { getAllCompanyApi } from "@/api/managementCenter/departmentPersonnel";
import { reactive, ref } from "vue";

export default function InitHook() {
  //表单数据
  const formState = reactive<AccountKeeper.FormState>({
    accountList: [
      //账户数组
      {
        accountProperties: "", //账户性质
        name: "", //户名
        deptAccountDtoList: [
          {
            shortName: "", //账户简称
            receiveAccount: "", //账号
            openBank: "", //开户银行
            bankName: "", //开户行名称
            currency: "", //币种
            sisterBankNum: "", //联行号
            paymentMethod: "", //收款方式
            isSyncBill: 0, //是否同步账单
            remark: "" //备注
          }
        ]
      }
    ],

    deptId: "" //所属经营单位
  });

  //表格数据
  const tableData = reactive([]);
  const getAllCompanyOpts = ref<{ label: string; value: string }>();
  //等待状态
  const loading = ref<boolean>(false);

  //表单ref
  const formDataRef = ref(null);

  const getAllCompanyHandle = () => {
    getAllCompanyApi({ status: 1, pageNum: 1, pageSize: 9999999, total: 0 }).then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        getAllCompanyOpts.value = data || [];
      }
    });
  };

  return {
    tableData,
    formState,
    loading,
    formDataRef,
    getAllCompanyHandle,
    getAllCompanyOpts
  };
}
